<template>
    <div class="main">
        <el-tabs class="tabs" type="border-card">
            <el-tab-pane v-for="(tab, index) in list" :key="tab.key" :label="tab.name">
                <tinymce v-if="list[index]" :height="600" v-model="list[index].value"></tinymce>
                <div v-if="rightsButtons['edit']" class="btn-container">
                    <el-button class="filter-item" type="success" @click="save(index)">保存</el-button>
                </div>
            </el-tab-pane>
        </el-tabs>
    </div>
</template>
<script>
    import Tinymce from '@/components/Tinymce'
    export default {
        name: 'helpList',
        components: {
            Tinymce
        },
        data(){
            return{
              listQuery: {
                type: 1,
                pageIndex: 1,
                pageSize: 100,
                isPage: 1
              },
              list: []
            }
        },
        created(){
            this.getList()
        },
        methods: {
            getList(){
                this.request({
                    url: '/bsnl-manage/managesetting/list-type',
                    method: 'get',
                    params: this.listQuery
                }).then(({data, totalCount}) => {
                    this.list = data;
                }).catch(err => {
                    console.log(err);
                    this.list = [];
                });
            },
            save(index){
                this.request({
                    url: '/bsnl-manage/managesetting/update',
                    method: 'post',
                    data: {
                      type:1,
                      ...this.list[index]
                    }
                }).then(() => {
                    this.$message({
                        type: 'success',
                        message: `【${this.list[index].name}】：保存成功`
                    })
                }).catch(err => {
                    console.log(err);
                    this.$message({
                        type: 'error',
                        message: err.message
                    })
                });
            }
        }
    }
</script>
<style>
    .btn-container{
        text-align: center;
        padding-top: 15px;
    }
</style>
